import utilService from './utilService'
import HttpService  from './httpService'
import constant from '../util/constant'
import validator from '../util/validator'

const userService = {
    login: function(data) {
        return new HttpService({
            method: 'post'
        }).request({
            url: constant.API.user_login,
            data: {
                username: data.username,
                password: md5(data.password + constant.maskCode)
            }
        })
    },
    loginOut: function() {

    },
    regsave: function(data = {}) {
        return new HttpService({
            method: 'post'
        }).request({
            url: constant.API.user_regsave,
            data: {
                telephone: data.telephone,
                userName: data.userName,
                ivc: data.ivc,
                verifyCode: data.verifyCode,
                pwd: md5(data.pwd + constant.maskCode),
                pwd2: md5(data.pwd2 + constant.maskCode),
                // 0:其它,1:PC,2:H5,3:android,4:IOS
                regSource: data.regSource,
                trackId: data.trackId
            }
        })
    },
    newUserWxBind: function(data = {}) {
        return new HttpService().request({
            url: constant.API.user_regsave,
            data: {
                userName: data.userName,
                telephone: data.telephone,
                verifyCode: data.verifyCode,
                pwd: data.pwd,
                pwd2: data.pwd,
                openId: data.openId,
                useOpen: data.useOpen,
                regSource: data.regSource
            }
        })
    },
    olderUserWxBind: function(data = {}) {
        return new HttpService({
            method: 'post'
        }).request({
            url: constant.API.user_wxlogin,
            data: {
                userName: data.userName,
                pwd: data.pwd,
                openId: data.openId
            }
        })
    },
    // 获取验证码
    sendCode: function(data = {}) {
        return new HttpService().request({
            url: constant.API.user_getverifycode,
            data: {
                key: data.key || data.telephone,
                ivc: data.ivc,
                type: data.type
            }
        })
    },
    // 检测验证码
    checkSMSCode: function(options = {}) {
        return new HttpService({
            method: 'post'
        }).request({
            url: constant.API.user_checkSMSCode,
            data: {
                key: options.key,
                verifyCode: options.verifyCode,
                type: options.type,
                checkRemove: true
            }
        })
    }
}
export default userService;